﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>驰骋工作流</title>
    <!-- 于庆海 -->
    <script language="JavaScript" src="../../Comm/JScript.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../../Comm/Gener.js"></script>
    <script type="text/javascript" src="../../Scripts/config.js"></script>
    <script type="text/javascript" language="javascript">
        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");
        });

        //初始化数据.
        function InitPage() {

            //设定枚举值下拉框.
            GenerBindEnumKey("DDL_BillFileType", "BillFileType", 0);
            GenerBindEnumKey("DDL_BillOpenModel", "BillOpenModel", 0);

            //初始化表格.
            $.ajax({
                type: 'post',
                async: true,
                url: Handler + "?DoType=Bill_Init&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') == 0) {
                        alert(data);
                        return;
                    }

                    data = JSON.parse(data);

                    var fk_BillTemplate = GetQueryString("FK_BillTemplate");
                    var currBill = null;

                    //生成列表.
                    //增加处理.
                    for (var i = 0; i < data.length; i++) {

                        if (fk_BillTemplate == data[i].No) {
                            currBill = data[i];
                        }

                        var newRow = "";
                        newRow = "<tr ><td class=Idx>" + i + "</td>";
                        newRow += "<td>" + data[i].No + "</td>";
                        newRow += "<td>" + data[i].Name + "</td>";
                        newRow += "<td><a href='" + Handler + "?DoType=Bill_Download&No=" + data[i].No + "'>" + data[i].TempFilePath + "</td>";

                        newRow += "<td>";
                        newRow += "<a href=\"javascript:Edit('" + data[i].No + "')\"><img src='/WF/Img/Btn/Edit.gif' border=0 />编辑</a>";
                        newRow += "<a href=\"javascript:Delete('" + data[i].No + "')\"><img src='/WF/Img/Btn/Delete.gif' border=0 />删除</a>";
                        newRow += "</td>";

                        newRow += "</tr>";

                        $("#Table1 tr:last").after(newRow);
                    }

                    //调用公共类库的方法:执行批量主表赋值
                    if (currBill != null)
                        GenerFullAllCtrlsVal(currBill);

                }
            });
        }

        function Delete(no) {

            if (window.confirm('您确定要删除吗？') == false)
                return;

            $.ajax({
                data: null,
                type: 'post',
                async: true,
                url: Handler + "?DoType=Bill_Delete&FK_BillTemplate=" + no + "&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {

                    if (data.indexOf('err@') >= 0) {
                        alert(data);
                        return;
                    }

                    window.location.href = window.location.href;
                    return;
                }
            });
        }

        function Edit(no) {

            var url = "Billing.htm?FK_BillTemplate=" + no + "&FK_Node=" + GetQueryString("FK_Node");
            window.location.href = url;
        }
        //ajax 提交
        function Btn_Save_Click2() {

            var checkBoxIDs = GenerCheckIDs(); //获得所有的 checkBox ID传入到后台去,用于解决checkbox控件，在没有被选择的时候，没有值的问题。
            var frmData = $("#cc").serialize();
            //alert(frmData); 

            $.ajax({
                data: frmData,
                type: 'post',
                async: true,
                url: Handler + "?DoType=Bill_Save&CheckBoxIDs=" + checkBoxIDs + "&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random(),
                dataType: 'html',
                success: function (data) {
                    if (data.indexOf('err@') >= 0) {
                        alert(data);
                        return;
                    }
                    alert(data);
                    window.location.href = window.location.href;
                    return;
                }
            });
        }

        function Btn_Save_Click() {

            var formData = new FormData($("#cc")[0]);
            $.ajax({
                url: Handler + "?DoType=Bill_Save&CheckBoxIDs=" + "&FK_Node=" + GetQueryString("FK_Node") + "&m=" + Math.random(),
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data.indexOf('err@') >= 0) {
                        alert(data);
                        return;
                    }
                    alert(data);
                    window.location.href = window.location.href;
                    return;
                }
            });
        }

        function Btn_New_Click() {

            document.getElementById("TB_No").value = "";
            document.getElementById("TB_Name").value = "";
        }
    </script>
</head>
<body>
    <form id="cc" enctype="multipart/form-data" method="post">
    <table style="width: 40%;">
        <caption>
            单据模版
        </caption>
        <tr>
            <td>
                编号
            </td>
            <td>
                <input type="text" id="TB_No" name="TB_No" readonly="1" />
            </td>
        </tr>
        <tr>
            <td>
                名称
            </td>
            <td>
                <input type="text" id="TB_Name" name="TB_Name" />
            </td>
        </tr>
        <tr>
            <td>
                类型
            </td>
            <td>
                <select id="DDL_BillFileType" name="DDL_BillFileType" />
            </td>
        </tr>
        <tr>
            <td>
                打开方式
            </td>
            <td>
                <select id="DDL_BillOpenModel" name="DDL_BillOpenModel" />
            </td>
        </tr>
        <tr>
            <td>
                文件
            </td>
            <td>
                <input type="file" name="bill"/>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" id="Btn_Save" runat="server" value="保存" onclick="Btn_Save_Click()" />
                <input type="button" id="Btn_New" runat="server" value="新建" onclick="Btn_New_Click()" />
            </td>
        </tr>
    </table>
    <br />
    <table style="width: 100%;" id="Table1">
        <caption>
            单据模版列表
        </caption>
        <tr>
            <th>
                序号
            </th>
            <th>
                编号
            </th>
            <th>
                名称
            </th>
            <th>
                路径
            </th>
            <th>
                操作
            </th>
        </tr>
    </table>
    </form>
</body>
</html>
